import random

# 生成随机数据
def generate_random_data():
    # 原保费收入
    original_premium_income = random.uniform(100000, 1000000)
    # 分出保费
    reinsurance_premium = random.uniform(10000, 100000)
    # 提取未到期责任准备金
    unearned_premium_reserve_extracted = random.uniform(5000, 50000)
    # 转回未到期责任准备金
    unearned_premium_reserve_reversed = random.uniform(2000, 20000)
    # 赔付支出
    claim_payment = random.uniform(50000, 500000)
    # 提取未决赔款准备金
    outstanding_claim_reserve_extracted = random.uniform(10000, 100000)
    # 转回未决赔款准备金
    outstanding_claim_reserve_reversed = random.uniform(5000, 50000)
    # 业务及管理费
    business_and_management_expenses = random.uniform(20000, 200000)
    # 手续费及佣金
    commission_and_fees = random.uniform(10000, 100000)
    # 分保费用
    reinsurance_expenses = random.uniform(5000, 50000)
    # 保险业务营业税金及附加
    insurance_business_taxes_and_surcharges = random.uniform(3000, 30000)
    # 摊回分保费用
    reinsurance_expenses_recovered = random.uniform(2000, 20000)

    return {
        'original_premium_income': original_premium_income,
        'reinsurance_premium': reinsurance_premium,
        'unearned_premium_reserve_extracted': unearned_premium_reserve_extracted,
        'unearned_premium_reserve_reversed': unearned_premium_reserve_reversed,
        'claim_payment': claim_payment,
        'outstanding_claim_reserve_extracted': outstanding_claim_reserve_extracted,
        'outstanding_claim_reserve_reversed': outstanding_claim_reserve_reversed,
        'business_and_management_expenses': business_and_management_expenses,
        'commission_and_fees': commission_and_fees,
        'reinsurance_expenses': reinsurance_expenses,
        'insurance_business_taxes_and_surcharges': insurance_business_taxes_and_surcharges,
        'reinsurance_expenses_recovered': reinsurance_expenses_recovered
    }

# 计算已赚保费
def calculate_earned_premium(data):
    return data['original_premium_income'] - data['reinsurance_premium'] - data['unearned_premium_reserve_extracted'] + data['unearned_premium_reserve_reversed']

# 计算赔付率
def calculate_loss_ratio(data):
    earned_premium = calculate_earned_premium(data)
    return ((data['claim_payment'] + data['outstanding_claim_reserve_extracted'] - data['outstanding_claim_reserve_reversed']) / earned_premium) * 100

# 计算综合费用率
def calculate_composite_expense_ratio(data):
    earned_premium = calculate_earned_premium(data)
    return ((data['business_and_management_expenses'] + data['commission_and_fees'] + data['reinsurance_expenses'] + data['insurance_business_taxes_and_surcharges'] - data['reinsurance_expenses_recovered']) / earned_premium) * 100

# 计算综合成本率
def calculate_composite_cost_ratio(data):
    earned_premium = calculate_earned_premium(data)
    numerator = (data['claim_payment'] + data['outstanding_claim_reserve_extracted'] - data['outstanding_claim_reserve_reversed'] +
                 data['business_and_management_expenses'] + data['commission_and_fees'] + data['reinsurance_expenses'] +
                 data['insurance_business_taxes_and_surcharges'] - data['reinsurance_expenses_recovered'])
    return (numerator / earned_premium) * 100

# 计算保费费用率
def calculate_premium_expense_ratio(data):
    return (data['business_and_management_expenses'] / data['original_premium_income']) * 100

# 计算手续费及佣金比率
def calculate_commission_ratio(data):
    return (data['commission_and_fees'] / data['original_premium_income']) * 100

# 计算分保费用比率
def calculate_reinsurance_expense_ratio(data):
    return (data['reinsurance_expenses'] / data['reinsurance_premium']) * 100

# 主函数
def main():
    data = generate_random_data()

    # 计算各项指标
    loss_ratio = calculate_loss_ratio(data)
    composite_expense_ratio = calculate_composite_expense_ratio(data)
    composite_cost_ratio = calculate_composite_cost_ratio(data)
    premium_expense_ratio = calculate_premium_expense_ratio(data)
    commission_ratio = calculate_commission_ratio(data)
    reinsurance_expense_ratio = calculate_reinsurance_expense_ratio(data)

    # 输出结果
    print(f"赔付率: {loss_ratio:.2f}%")
    print(f"综合费用率: {composite_expense_ratio:.2f}%")
    print(f"综合成本率: {composite_cost_ratio:.2f}%")
    print(f"保费费用率: {premium_expense_ratio:.2f}%")
    print(f"手续费及佣金比率: {commission_ratio:.2f}%")
    print(f"分保费用比率: {reinsurance_expense_ratio:.2f}%")

if __name__ == "__main__":
    main()